package com.zl.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @author zl
 * @date 2023/3/22
 * @apiNote
 */

/**
 *  自定义限制
 */
@Configuration
public class RequestLimitConfig {

    // 针对某一个ip来限制  /doLogin  每一个ip 10S只能访问三次
    @Bean
    public KeyResolver ipkeyResolver(){
        return exchange -> Mono.just(exchange.getRequest().getHeaders().getHost().getHostString());
    }
    // 针对这个路径   /doLogin
    @Bean
    public KeyResolver apikeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getPath().value());
    }

}
